<?php defined('SYSPATH') or die('No direct script access.');

/**
 * 新闻资讯
 * Class Controller_Pc_Api_V2_News
 */
class Controller_Pc_Api_V2_News extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_News
     */
    private $validation;

    /**
     * 服务
     * @var Service_Api_News
     */
    private $service;


    public function before()
    {
        parent::before();

        // 验证
        $this->validation = Request_Api_V2_Factory::create('news', $this->request_params);

        // 服务
        $this->service = new Service_Api_News();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 分类
    public function action_get_attr()
    {
        try {
            $this->result['data'] = $this->service->get_attr();
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 列表
    public function action_get_list()
    {
        try {
            $this->validation->get_list()->check();

            $this->result['data'] = $this->service->get_list($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 详情
    public function action_get_detail()
    {
        try {
            $this->validation->get_detail()->check();

            $this->result['data'] = $this->service->get_detail($this->request_params);
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

}